package com.zyh.lambda;

/**
 * @Author zyh
 * @Date 2024/8/15 16:03
 * @Description lambda
 */

public class LambdaDemo1 {
    //简化写法
    public static void main(String[] args) {
        //1
        NoReturnNoParam noReturnNoParam=()-> System.out.println("无参无返回值方法");
        noReturnNoParam.method();

        //2
        NoReturnOneParam noReturnOneParam=a -> System.out.println(a+"一个参数无返回值方法");
        noReturnOneParam.method(2);

        //3
        NoReturnMoreParam noReturnMoreParam=(a,b)-> System.out.println(a+b);
        noReturnMoreParam.method(3,"zyh");

        //4
        ReturnNoParam returnNoParam=()->4;
        int method = returnNoParam.method();
        System.out.println("method = " + method);

        //5
        ReturnOneParam returnOneParam=name -> Integer.valueOf(name);
        Integer method1 = returnOneParam.method("5");
        System.out.println("method1 = " + method1);

        //6
        ReturnMoreParam returnMoreParam=(name,age)-> Integer.valueOf(name)+age;
        Integer method2 = returnMoreParam.method("6", 1);
        System.out.println("method2 = " + method2);
    }

    //标准写法
    public static void main1(String[] args) {
        //1.
        NoReturnNoParam noReturnNoParam=()->{
            System.out.println("无参无返回值接口");
        };
        noReturnNoParam.method();

        //2.
        NoReturnOneParam noReturnOneParam=(int a)->{
            System.out.println("a = " + a);
        };
        noReturnOneParam.method(3);

        //3
        NoReturnMoreParam noReturnMoreParam=(int a,String b)->{
            System.out.println("a = " + a);
            System.out.println("b = " + b);
        };
        noReturnMoreParam.method(4,"zyh");

        //4.
        ReturnNoParam returnNoParam=()->{
            System.out.println("无参有返回值方法");
            return 4;
        };
        returnNoParam.method();

        //5
        ReturnOneParam returnOneParam=(String name)->{
            System.out.println("name = " + name);
            return Integer.valueOf(name)+5;
        };
        Integer method = returnOneParam.method("10");
        System.out.println("method = " + method);

        //6
        ReturnMoreParam returnMoreParam=(String name,Integer age)->{
            System.out.println("name = " + name);
            return age;
        };
        Integer zyh = returnMoreParam.method("zyh", 6);
        System.out.println("zyh = " + zyh);
    }
}
interface NoReturnNoParam{
    void method();
}
interface NoReturnOneParam{
    void method(int a);
}
interface NoReturnMoreParam{
    void method(int a,String b);
}
interface ReturnNoParam{
    int method();
}
interface ReturnOneParam{
    Integer method(String name);
}
interface ReturnMoreParam{
    Integer method(String name,Integer age);
}
